package com.qf.wxpay.controller;

import com.github.wxpay.sdk.WXPayConfig;
import com.qf.openapi2204.common.vo.R;
import com.qf.wxpay.utils.WxPayUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.InputStream;

@RestController
public class WayxinController {

    @GetMapping("/getpayurl")
    public R getPayUrl(String costomerid,String orderid,String ordercontent,Integer totalamout) throws Exception {

        WXPayConfig config = getWeixinCongfig(costomerid);

        String payUrl = WxPayUtils.getPayUrl(orderid, totalamout, orderid, config);

        R ok = R.ok(payUrl);
        return ok;
    }

    private WXPayConfig getWeixinCongfig(String costomerid) {

        // 根据 costomerid 查询出该用户的微信商户号、appid、appkey等信息

        WXPayConfig config = new WXPayConfig() {
            @Override
            public String getAppID() {
                return "wx632c8f211f8122c6";
            }

            @Override
            public String getMchID() {
                return "1497984412";
            }

            @Override
            public String getKey() {
                return "sbNCm1JnevqI36LrEaxFwcaT0hkGxFnC";
            }

            @Override
            public InputStream getCertStream() {
                return null;
            }

            @Override
            public int getHttpConnectTimeoutMs() {
                return 0;
            }

            @Override
            public int getHttpReadTimeoutMs() {
                return 0;
            }
        };
        return config;
    }

}
